<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
        Promise.all方法:
            接收一个数组(原则上是iterable类型)作为参数
            all方法默认返回pending状态的promise实例
            当所有的promise实例完成,返回fulfilled状态的实例,值为所有成功的值组成的数组
            当其中有一个promise实例执行失败,则all方法返回失败的promise实例,值为错误值
        */
        const p1 = new Promise((resolve, reject) => {
            try {
                console.log('请求获取A');
                // throw new Error('A错误')
                setTimeout(() => {
                    console.log('A数据获取成功');
                    resolve('A数据')
                }, 1000);
            } catch (e) {
                reject(e.message)
            }
        })
        const p2 = new Promise((resolve, reject) => {
            try {
                console.log('请求获取B');
                // throw new Error('B错误')
                setTimeout(() => {
                    console.log('B数据获取成功');
                    resolve('B数据')
                }, 1000);
            } catch (e) {
                reject(e.message)
            }
        })
        const p3 = new Promise((resolve, reject) => {
            try {
                console.log('请求获取C');
                // throw new Error('C错误')
                setTimeout(() => {
                    console.log('C数据获取成功');
                    resolve('C数据')
                }, 1000);
            } catch (e) {
                reject(e.message)
            }
        })

        const nn= Promise.all([p1,p2,p3])
        console.log('nn',nn);
        nn.then(va=>{
            console.log('全部成功');
        }).catch(re=>{
            console.log('有错误',re);
        })
    </script>
</body>

</html>